import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';
import { useI18n } from 'vue-i18n';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'auditObjectName',
    label: '审核对象名称',
  },
  {
    component: 'Input',
    fieldName: 'totalItems',
    label: '审核项总数',
  },
  {
    component: 'Input',
    fieldName: 'auditedItems',
    label: '已审核数',
  },
  {
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_TASK_STATUS 便于维护
      options: getDictOptions('audit_task_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    fieldName: 'taskStatus',
    label: '任务状态',
  },
  {
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'startTime',
    label: '任务开始时间',
  },
  {
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'endTime',
    label: '任务结束时间',
  },
];

// columns getter化，支持国际化和字典渲染
export const columns: () => VxeGridProps['columns'] = () => {
  const { t } = useI18n();
  return [
  { type: 'checkbox', width: 60 },
  {
      title: t('pages.auditTask.taskId', '审核任务ID'),
    field: 'taskId',
  },
  {
      title: t('pages.auditTask.auditObjectName', '审核对象名称'),
    field: 'auditObjectName',
  },
  {
      title: t('pages.auditTask.totalItems', '审核项总数'),
    field: 'totalItems',
  },
  {
      title: t('pages.auditTask.auditedItems', '已审核数'),
    field: 'auditedItems',
  },
  {
      title: t('pages.auditTask.taskStatus', '任务状态'),
    field: 'taskStatus',
    slots: {
        default: ({ row }) => renderDict(row.taskStatus, 'audit_task_status'),
    },
  },
  {
      title: t('pages.auditTask.startTime', '任务开始时间'),
    field: 'startTime',
  },
  {
      title: t('pages.auditTask.endTime', '任务结束时间'),
    field: 'endTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
      title: t('pages.common.action', '操作'),
    width: 180,
  },
];
};

export const modalSchema: FormSchemaGetter = () => [
  {
    label: '审核任务ID',
    fieldName: 'taskId',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '审核对象名称',
    fieldName: 'auditObjectName',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '审核项总数',
    fieldName: 'totalItems',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '已审核数',
    fieldName: 'auditedItems',
    component: 'Input',
    rules: 'required',
  },
  {
    label: '任务状态',
    fieldName: 'taskStatus',
    component: 'RadioGroup',
    componentProps: {
      // 可选从DictEnum中获取 DictEnum.AUDIT_TASK_STATUS 便于维护
      options: getDictOptions('audit_task_status'),
      buttonStyle: 'solid',
      optionType: 'button',
    },
    rules: 'selectRequired',
  },
  {
    label: '任务开始时间',
    fieldName: 'startTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    label: '任务结束时间',
    fieldName: 'endTime',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
];
